package com.zuohuaipan.headine.fragment;


import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.zuohuaipan.headine.R;
import com.zuohuaipan.lazyviewpager_master.LazyFragmentPagerAdapter;
import com.zuohuaipan.lazyviewpager_master.LazyViewPager;
import com.zuohuaipan.pagerslidingtabstrip.PagerSlidingTabStrip;

public class Video_Fragment extends Fragment {
    public LazyViewPager vp;
    public PagerSlidingTabStrip ps;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_video_, container, false);
        //初始化
        initView(view);
        return view;
    }

    private void initView(View view) {
        vp = (LazyViewPager) view.findViewById(R.id.video_vp);
        ps = (PagerSlidingTabStrip) view.findViewById(R.id.video_ps);
        //设置适配器
        vp.setAdapter(new MyAdapter(getChildFragmentManager()));
        //绑定,实现联动
        ps.setViewPager(vp);
        ps.setTextSize(50);
        ps.setIndicatorColor(Color.RED);
        ps.setIndicatorHeight(4);

    }

    //创建适配器 继承lazyfragmentpageradapter
    class MyAdapter extends LazyFragmentPagerAdapter {
        private final String[] TITLES = {"热点视频", "娱乐视频", "搞笑视频", "精品视频"};

        String[] video_type = new String[]{"list", "list", "list", "list"};
        String[] video_typeid = new String[]{"V9LG4B3A0", "V9LG4CHOR", "V9LG4E6VR", "00850FRB"};

        /**
         * 必须重写构造器
         *
         * @param fm
         */
        public MyAdapter(FragmentManager fm) {
            super(fm);
        }

        /**
         * 必须实现
         *
         * @param position
         * @return
         */
        @Override
        public CharSequence getPageTitle(int position) {
            return TITLES[position];
        }

        @Override
        protected Fragment getItem(ViewGroup container, int position) {
            return NwsVideoFragment.newInstance(video_type[position], video_typeid[position]);
        }

        @Override
        public int getCount() {
            return TITLES.length;
        }
    }

}
